/*
	DIMGA
	Distributed Island Model Genetic Algorithm 

	Copyright (c) 2006 Nikola Sivacki nsivacki@gmail.com

	This program is free software; you can redistribute it and/or
	modify in under the terms of the GNU General Public Licence as
	published by the Free Software Foundation; either version 2 of
	the Licence, or [at your option] any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAT PURPOSE. See the
	GNU General Public Licence for more details.

	You should have received a copy of the GNU General Public Licence
	along with this program; if not, write to the Free Software 
	Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _NETUTIL_HPP
#define _NETUTIL_HPP


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

// This method is a quick way to retrieve the address in binary form from the dot delimited string form 
unsigned long getaddr(const char* _pcadr)

{
	long ret = 0;

	int val[4];
	int ofs[4];
	int ofsofs=1;
	ofs[0] = -1;
	
	char tmp[strlen(_pcadr)];
	strcpy(tmp, _pcadr);
	
	for(int i = 0 ; i < strlen(_pcadr); i++)
	{
		if (tmp[i] == '.')
			{
				ofs[ofsofs++] = i;
				tmp[i] = 0;
				
				val[ofsofs-2] = atoi(tmp + ofs[ofsofs-2] + 1);
				ret = ret | (val[ofsofs-2] << (3 - (ofsofs-2))*8);
			}
	}

	val[3] = atoi(tmp + ofs[3] + 1);
	ret = ret | val[3];

	return ret;
}

#endif
